home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRICMPL.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  3KB  |  133 lines

  1. StdGrp        group    StdLib, StdData
  2. ;
  3. StdData        segment    para public 'sldata'
  4.         extrn    $uprtbl:byte
  5. StdData        ends
  6. ;
  7. stdlib        segment    para public 'slcode'
  8.         assume    cs:StdGrp
  9. ;
  10. ;
  11. ; strcmpl- Compares the string pointed at by es:si to the string following
  12. ;       the call instruction.
  13. ;
  14. ; inputs:
  15. ;
  16. ;    es:si-    First string (The string to compare)
  17. ;    cs:rtn-    Second string (The string to compare against)
  18. ;
  19. ;    e.g.,
  20. ;        "if (es:si < cs:rtn) then ..."
  21. ;
  22. ; returns: 
  23. ;
  24. ;    ax- index into strings where they differ (points at the zero byte
  25. ;        if the two strings are equal).
  26. ;    Condition codes set according to the string comparison.  You should
  27. ;    use the unsigned branches (ja, jb, je, etc.) after calling this
  28. ;    routine.
  29. ;
  30.         public    sl_stricmpl
  31. ;
  32. sl_stricmpl    proc    far
  33.         push    bp
  34.         mov    bp, sp
  35.         push    es
  36.         push    ds
  37.         push    bx
  38.         push    cx
  39.         push    si
  40.         push    di
  41.         mov    ax, es
  42.         mov    ds, ax
  43.         les    di, 2[bp]
  44.         lea    bx, stdgrp:$uprtbl
  45. ;
  46. ; In order to preserve the direction flag across this call, we have to
  47. ; test whether or not it is set here and execute two completely separate
  48. ; pieces of code (so we know which state to exit in.  Unfortunately, we
  49. ; cannot use pushf to preserve this flag since we need to return status
  50. ; info in the other flags.
  51. ;
  52.         pushf
  53.         pop    ax
  54.         test    ah, 4        ;Test direction bit.
  55.         jnz    DirIsSet
  56. ;
  57. ; Compute the length of the string following the CALL instruction:
  58. ;
  59.         cld
  60.         mov    al, 0
  61.         mov    cx, 0ffffh
  62.     repne    scasb
  63.         xchg    di, 2[bp]    ;Save as new return address.
  64. ;
  65.         xor    cx, cx        ;Set char index to zero.
  66. sclp:        lodsb
  67.         xlat    StdGrp:$uprtbl
  68.         mov    ah, al
  69.         mov    al, es:[di]
  70.         xlat    StdGrp:$uprtbl
  71.         cmp    ah, al        
  72.         jne    scNE        ;If strings are <>, quit.
  73.         inc    cx            ;Increment index into strs.
  74.         inc    di        ;Incrment str2 ptr.
  75.         cmp    al, 0        ;Check for end of strings.
  76.         jne    sclp
  77.         pushf
  78.         dec    cx
  79.         popf
  80. ;
  81. scNE:        mov    ax, cx
  82.         pop    di
  83.         pop    si
  84.         pop    cx
  85.         pop    bx
  86.         pop    ds
  87.         pop    es
  88.         pop    bp
  89.         ret            ;Return with direction flag clear.
  90. ;
  91. ;
  92. DirIsSet:    cld
  93.         mov    al, 0
  94.         mov    cx, 0ffffh
  95.     repne    scasb
  96.         xchg    di, 2[bp]    ;Save as new return address.
  97. ;
  98.         xor    cx, cx        ;Set char index to zero.
  99. sclp2:        lodsb
  100.         xlat    StdGrp:$uprtbl
  101.         mov    ah, al
  102.         mov    al, es:[di]
  103.         xlat    StdGrp:$uprtbl
  104.         cmp    ah, al        
  105.         jne    scNE2        ;If strings are <>, quit.
  106.         inc    cx            ;Increment index into strs.
  107.         inc    di        ;Incrment str2 ptr.
  108.         cmp    al, 0        ;Check for end of strings.
  109.         jne    sclp2
  110.         pushf
  111.         dec    cx
  112.         popf
  113. ;
  114. scNE2:        mov    ax, cx
  115.         pop    di
  116.         pop    si
  117.         pop    cx
  118.         pop    bx
  119.         pop    ds
  120.         pop    es
  121.         pop    bp
  122.         std
  123.         ret            ;Return with direction flag set.
  124. ;
  125. ;
  126. ;
  127. sl_stricmpl    endp
  128. ;
  129. ;
  130. stdlib        ends
  131.         end
  132.